package com.concurrency.waitNotify;

import java.util.List;
import java.util.Vector;

public class Producer extends Thread{
	List<String> goods;
	
	public Producer(List<String> goods){
		this.goods = goods;
	}


	public void run() {
		
		synchronized(goods){
			while(true){

				try {
					while(goods.size()==5){
						goods.wait();//该线程在此暂停！同时释放goods锁。
					}
					goods.add("a");
					Thread.sleep(500);
					System.out.println("Producer当前goods数量:"+goods.size());
					goods.notify();//通知其他线程访问goods。本线程仍持有goods锁。
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}



	}

}
